package com.atguigu.springcloud.order.controller;

import com.atguigu.springcloud.framework.common.api.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author lenovo
 * @version 1.0
 * @date 2020/11/12 9:58
 */
@RestController
@Slf4j
@RequestMapping("consumer")
public class OrderController {

//    private static final String PAYMENT_URL = "http://localhost:8001";
    private static final String PAYMENT_URL = "http://cloud-payment-service";

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/payment/get/{id}")
    public ApiResult getPayment(@PathVariable Long id){
        return restTemplate.getForObject(PAYMENT_URL+"/payment/get/"+id,ApiResult.class);
    }

    @GetMapping("consul")
    public ApiResult consul() {
        return restTemplate.getForObject(PAYMENT_URL+"/payment/consul",ApiResult.class);
    }

}
